﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZFSData;
using ZFSData.Manager;
using ZFSInterface.User;

namespace ZFSBusiness
{

    /// <summary>
    /// 用户管理
    /// </summary>
    public class UserManager : IUser
    {
        private static UserManager instance = null;

        public static UserManager Instance()
        {
            if (instance == null)
                instance = new UserManager();
            return instance;
        }

        /// <summary>
        /// 新增用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Add(tb_User user)
        {
            #region Defaule Value

            user.IsLocked = 0;
            user.FlagAdmin = "0";
            user.FlagOnline = "0";
            user.LoginCounter = 0;
            user.CreateTime = DateTime.Now;

            #endregion
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().Add(user);
        }

        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public bool Delete(string account)
        {
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().Delete(account);
        }

        /// <summary>
        /// 是否存在
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public bool Exits(string account)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 查询用户
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public tb_User Find(string account)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 查找所有用户
        /// </summary>
        /// <returns></returns>
        public List<tb_User> FindAll()
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取用户权限
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public List<View_UserAuthority> GetAuthority(string account)
        {
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().GetAuthority(account);
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public tb_User GetUser(string account)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 获取指定用户
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public List<tb_User> GetUsers(string search)
        {
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().GetUsers(search);
        }

        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public tb_User Login(string account, string password)
        {
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().Login(account, password);
        }

        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="account"></param>
        public void Logout(string account)
        {
            throw new NotImplementedException();
        }

        /// <summary>
        /// 修改用户信息
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool Update(tb_User user)
        {
            FactoryManager f = new FactoryManager();
            return f.GetUserManager().Update(user);
        }

    }
}
